import os

from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from settings import BASE_DIR, PREFIX


class BaseConfig:
    APP_NAME = "TASK-APP"


class DevelopmentConfig(BaseConfig):
    # 存储位置
    SCHEDULER_JOBSTORES = {'default': SQLAlchemyJobStore(url=PREFIX + os.path.join(BASE_DIR, 'data-dev.db'))}

    # 设置时区
    SCHEDULER_TIMEZONE = 'Asia/Shanghai'

    # 线程池配置
    SCHEDULER_EXECUTORS = {'default': {'type': 'threadpool', 'max_workers': 20}}

    SCHEDULER_JOB_DEFAULTS = {
        'coalesce': False,  # False 系统恢复后，补偿全部的任务次数
        'max_instances': 3  # 同一个任务同一时间最多只能有n个实例在运行
    }

    # 调度器开关,要开启A才能够用api的形式去查看和批改定时工作
    SCHEDULER_API_ENABLED = True



class ProductionConfig(BaseConfig):
    pass


config = {
    'development': DevelopmentConfig,
    'production': ProductionConfig,
}
